<template>
  <d2-container>
    <template slot="header">WELCOME</template>
    <el-row class="d2-mb-10">
      <el-button>测试按钮</el-button>
      <el-button type="primary">主要</el-button>
      <el-button type="success">成功</el-button>
      <el-button type="info">信息</el-button>
      <el-button type="warning">警告</el-button>
      <el-button type="danger">危险</el-button>
    </el-row>

     <!-- 搜索框 -->
    <el-select v-model="value" placeholder="请选择"
               :change="change_Select(value)"
    >
      <el-option
          v-for="item in options"

          :key="item.value"
          :label="item.label"
          :value="item.value">
      </el-option>
    </el-select>
    <el-input placeholder="请输入内容" v-model="search_Input" class="input-with-select">
      <el-button slot="append" icon="el-icon-search" @click="search_Click()"></el-button>
    </el-input>

      <!-- 表格区域 -->
    <el-table
        :data="tableData"
        stripe
        style="width: 100%">
      <el-table-column
          prop="username"
          label="昵称"
          width="100">
      </el-table-column>
      <el-table-column
          prop="userrole"
          label="用户角色"
          width="100">
        <template slot-scope="scope">
          <el-tag  v-if="scope.row.userrole === 1">大哥</el-tag>
          <el-tag type="info" v-else>小弟</el-tag>
        </template>
      </el-table-column>
      <el-table-column
          prop="useraccount"
          label="账号"
          width="100px">
      </el-table-column>
      <el-table-column
          prop="avatarurl"
          label="头像"
          width="180">
      </el-table-column>
      <el-table-column
          prop="gender"
          label="性别"
          width="50px">
      </el-table-column>
      <el-table-column
          prop="phone"
          label="电话号">
      </el-table-column>
      <el-table-column
          prop="email"
          label="邮箱">
      </el-table-column>
      <el-table-column
          prop="userstatus"
          label="用户状态">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.userstatus === 0">正常</el-tag>
          <el-tag type="danger" v-else>异常</el-tag>
        </template>
      </el-table-column>
      <el-table-column
          prop="createtime"
          label="创建时间">
      </el-table-column>
      <el-table-column
          prop="updatetime"
          label="修改时间">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="">
          <el-button type="primary" icon="el-icon-edit" circle></el-button>
          <el-button  type="danger" icon="el-icon-delete" circle></el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[5, 8, 10]"
        :page-size="100"
        layout="total, sizes, prev, pager, next, jumper"
        :total="queryInfo.total">
    </el-pagination>

    <template slot="footer">
      <footer-link/>
    </template>
  </d2-container>
</template>

<script>
import RouteInfo from './componnets/RouteInfo'
import FooterLink from './componnets/FooterLink'
import {postSearchUserData} from '@/api/index.js';

export default {
  // 如果需要缓存页面
  // name 字段需要设置为和本页路由 name 字段一致
  name: 'demo1',
  components: {
    RouteInfo,
    FooterLink
  },
  data(){
    return{
      options: [{
        value: 'userName',
        label: '昵称'
      }, {
        value: 'userAccount',
        label: '账号'
      }, {
        value: 'genDer',
        label: '性别'
      }, {
        value: 'phone',
        label: '电话'
      }, {
        value: 'userStatus',
        label: '状态'
      }],
      value: '',
      //用户数据
      tableData: [],
      //分页数据
      queryInfo:{
        query:"",
        pagenum:1,
        pagesize:5,
        total:0,
        value:""
      },
      //搜索框数据
      search_Input:""
    }
  },
  mounted(){
  this.getUserData()
  },
  methods:{
    /**
     * 用户数据获取
     * @param userName
     */
    getUserData(){
      postSearchUserData(this.queryInfo.query,this.queryInfo.pagenum,this.queryInfo.pagesize,this.queryInfo.value).then(response =>{
         if (response==null){
           this.$message.error("无数据!")
           return;
         }else {
           console.log(response)
           this.tableData=response.records
           this.queryInfo.total=response.total
         }
      })
    },
    /**
     * 分页方法
     */
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.queryInfo.pagesize=val;
      this.getUserData();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.queryInfo.pagenum=val;
      this.getUserData();
    },
    change_Select(value){
      console.log(value)
     this.queryInfo.value = value;
    },
    /**
     * 搜索按钮
     */
    search_Click(){
      this.queryInfo.query=this.search_Input;
      this.getUserData();
    }
  }
}
</script>

<style scoped>
.el-select {
  width: 100px;
  border-radius: 1px !important;
}
.el-input{
  width: 50%;
  position: absolute;
  left: 119px;
}
.el-table{
  margin-top: 10px;
}
</style>
